package com.shuwen.gcdj.controller.sys.log;

import com.shuwen.gcdj.bean.Enum.LogModule.LogModuleResp;
import com.shuwen.gcdj.bean.Enum.LogType.LogTypeResp;
import com.shuwen.gcdj.bean.sys.log.request.LogPageReq;
import com.shuwen.gcdj.bean.sys.log.response.LogResp;
import com.shuwen.gcdj.common.annotation.JWTAuth;
import com.shuwen.gcdj.common.api.CommonPage;
import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.common.enums.LogModuleEnum;
import com.shuwen.gcdj.common.enums.LogTypeEnum;
import com.shuwen.gcdj.common.sysLog.AddSysLogUtil;
import com.shuwen.gcdj.controller.AuthController;
import com.shuwen.gcdj.dto.account.InitUserDto;
import com.shuwen.gcdj.service.sys.log.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author :杨云山
 * @date : 2023/3/15 9:30
 */

@Api(tags = "系统日志 - 日志管理")
@RestController
@RequestMapping("/sys")
@Slf4j
public class LogController extends AuthController {

   @Autowired
   private LogService logService;
   @Autowired
   private AddSysLogUtil addSysLogUtil;


    @ApiOperation(value = "分页获取所有日志")
    @PostMapping(value = "/pageLogList")
    @ResponseBody
    @JWTAuth
    public CommonResult<CommonPage<LogResp>> pageLogList(HttpServletRequest request, @RequestBody LogPageReq req) {
        InitUserDto initUserDto = initUser(request);
        log.info("initUserDto = {}", initUserDto);
        return CommonResult.success(CommonPage.restPage(logService.getPageLogList(req)));
    }

    @ApiOperation(value = "获取所有日志模块")
    @GetMapping(value = "/getLogModuleList")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<LogModuleResp>>  getLogModuleList(HttpServletRequest request) {
        List<LogModuleResp> list = LogModuleEnum.getList();

        return CommonResult.success(list);
    }

    @ApiOperation(value = "获取所有日志类型")
    @GetMapping(value = "/getLogTypeList")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<LogTypeResp>> getLogTypeList(HttpServletRequest request) {
        List<LogTypeResp> list = LogTypeEnum.getList();

        return CommonResult.success(list);
    }

}
